<?php
// +----------------------------------------------------------------------
// | 微信预定地址二维码
// +----------------------------------------------------------------------
include('/var/www/html/new/d/common/auth.php');
include('/var/www/html/new/d/class/Member.php');
include('/var/www/html/new/d/module/phpqrcode/phpqrcode.php');

$ac = $GLOBALS['_ac'];
$pw = $GLOBALS['_pw'];
$s  = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

$memberSID = $_SESSION['sid'];

// 是否有二级域名
$sql = "select `M_account_domain` from `pft_member_domain_info` where fid=$memberSID limit 1";
$GLOBALS['le']->query($sql);
$GLOBALS['le']->fetch_assoc();
if(!($domain=$GLOBALS['le']->f('M_account_domain'))){

	$shop = array(
		'fid'=>$_SESSION['sid'],
		'M_account_domain'=>$_SESSION['saccount'],
		'M_domain'=>$_SESSION['saccount'],
		'M_logo1'=>'http://www.12301.cc/shops/images/default/index_logo.png',
		'M_logo2'=>'http://www.12301.cc/shops/images/default/index_logo.png',
		'M_banner'=>'http://www.12301.cc/shops/images/default/login_banner_b.jpg',
		'M_tel'=>'400-99-22301',
		'M_addr'=>'联系地址:福建省福州市鼓楼区西二环218号伯爵大酒店6楼',
	);
	
	$sql="insert into `pft_member_domain_info` set fid={$shop['fid']},M_account_domain='{$shop['M_account_domain']}',M_domain='{$shop['M_domain']}',M_logo1='{$shop['M_logo1']}',M_logo2='{$shop['M_logo2']}',M_banner='{$shop['M_banner']}',M_tel='{$shop['M_tel']}',M_addr='{$shop['M_addr']}',createtime=now()";
	$GLOBALS['le']->query($sql);
	$domain = $_SESSION['saccount'];
}

// 链接地址
$lid = abs($_REQUEST['lid']);
$redirect = "http://$domain.12301.cc/wx/html/p.html?lid=$lid";
if($_REQUEST['act']=="download"){//下载图片
	ob_end_clean();
	$file = @file_get_contents("http://10.160.4.140/new/d/module/phpqrcode/qr.php?text=".urlencode($redirect));
	header('Content-type: image/png'); 
	header("Content-Disposition:attachment;filename=".time()."二维码.png");
	exit($file);
}




$m = new Member($s,$memberSID);
$products = $m->salePros($lid);



$land = array();
$date = date('Y-m-d');
foreach($products as $k=>$ticket){ // 处理价格
    $xml = $s->Dynamic_Price_And_Storage('',$ticket['pid'],$date,1,1,1);
    if($xml==105 || $xml==1065) continue;// 没有价格表示没有出售
    $object = simplexml_load_string($xml);
    $uprice= (string)$object->Rec->UUsprice;
    $ticket['uprice'] = $uprice/100;
    $ticket['storage'] = (string)$object->Rec->UUstorage;
    // 景区信息
    if(!$land['ltitle']){
        $land['p_type'] = $ticket['p_type'];
        $land['ltitle'] = $ticket['title'];
        $land['sapply_did'] = $ticket['sapply_did'];
        $land['imgpath'] = 'http://www.12301.cc/'.$ticket['imgpath'];
    }
    $land['tickets'][] = $ticket;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://www.12301.cc/js/jquery-1.8.0.min.js"></script>
</head>
<title><?=$products[0]['ltitle']?>二维码</title>
<style>
*{ margin:0px;padding:0px}
body{font-size:12px; color:#666}
.clay{ width:660px;  margin:100px auto; background: #E5E5E5; overflow: auto;  -moz-border-radius: 5px; border-radius: 5px;} /*background:url(images/dcode_back.png) no-repeat; overflow: auto; background-size: 100% 100%;}*/
.fL{ float:left;width:180px; margin:80px 40px; }
.fL p{width:170px; text-align:center; margin-top:5px;}
.fR{ float:left; width:350px; padding:10px; padding-top:80px;}
.img{padding:20px; width:130px; background:#fff;}
.img img{margin:0 auto;}
h3{margin-bottom:10px;}
table{border-spacing:0px; border-collapse:collapse;width:100%; margin-bottom:10px; text-align:center;}
table th{ font-weight:normal;}
table th,table td{ border:1px solid ; padding:3px; }
p{line-height:20px;}
body a.link,a.link:visited{color:#008EC1;text-decoration:none;}
body a.link:hover{color:#008EC1}
#msg{color:red};
</style>
<body>
<div class="clay">
	<div class="fL">
		<h3>手机预订产品二维码：</h3>
		<div class="img">
			<!--<img width="130" src="<?//=$code_img?>"/>-->
			<img width="130" src="http://www.12301.cc/module/phpqrcode/qr.php?text=<?=$redirect?>"/>
		</div>
		<p>
			<a class="link" href="?lid=<?=$lid?>&act=download">下载图片</a>
			|
			<a class="link" href="#" id="code_link" link="<?=$redirect?>">显示链接</a>
		</p>
		<p id="msg"></p>
	</div>
	<div class="fR">
		<h3>产品名称：<?=$land['ltitle']?></h3>
		<table>
			<tr>
				<th>类别</th>
				<th>门市价</th>
				<th>优惠价</th>
			</tr>
			<?if(count($land['tickets'] ))
			foreach($land['tickets'] as $row){?>
			<tr>
				<td><?=$row['ttitle']?></td>
				<td><?=$row['tprice']?></td>
				<td><?=$row['uprice']?></td>
			</tr>
			<?}?>
		</table>
		<p>使用说明：</br>
		1.此二维码可印刷、显示于各种杂志、报纸、电视等宣传资料上，提供游客手机拍码预订相关旅游产品。</br>
		2.从登陆分销账号下载的二维码，游客拍码预订后的订单、利润将自动记录给此分销商。</br>
		<span style="color:red">3.如果分销商没有将产品开启转供应，则产品不会显示出来。</span></br>
		</p>
	</div>
</div>
<script>
	$("#code_link").click(function(){
		var txt=$(this).attr("link");
		if (window.clipboardData) {
			window.clipboardData.clearData();
			if(window.clipboardData.setData("text", txt)) alert("复制成功")
		} else {
			$("#msg").html("二维码链接:"+txt);
		}
		return false;
	})
</script>
</body>
</html>